<?php
/**
 * Created by PhpStorm OF Administrator.
 * User: YUYI
 * Date: 2018/7/31 0031
 * Time: 下午 5:57
 * Administrator
 */

namespace app\api\controller;


use app\common\service\QcloudCosUpload;

class File extends Base
{
    public function upload()
    {
        $path = ROOT_PATH.'public/user/'.md5(input('user_id'));
        $type = input('type');
        if (!is_dir($path)){
            mkdir($path);
        }
        list($name,$format) = explode('.',$_FILES['banner']['name']);
        $qcloudres = QcloudCosUpload::upload($_FILES['banner']['tmp_name'],md5($this->user->userId.$type).'.'.$format);
        $res1 = $this->ue->save($type == 'head'?['user_head_img_url'=>$qcloudres['ObjectURL']]:['user_banner_img_url'=>$qcloudres['ObjectURL']]);
        if ($res1!==false){
            return $this->successInfo('成功',['url'=>$qcloudres['ObjectURL']]);
        }else{
            return $this->errorInfo('失败');
        }
    }
}